pacman::p_load(ggplot2, dplyr, magrittr, openxlsx,ggpubr)

#dat2 <- "C:/Users/xueyj/Documents/WeChat Files/wxid_0428974290012/FileStorage/File/2020-11/96434541_0_上策马桶盖问卷调查_4_2.xlsx" %>%
#  read.delim(sep = "\t",header = TRUE)

#install.packages("D:/languages/Rlib/openxlsx_4.2.3.tar.gz")

#da <- "C:/Users/xueyj/Documents/WeChat Files/wxid_0428974290012/FileStorage/File/2020-11/96434541_0_上策马桶盖问卷调查_4_2.xlsx" %>%
#  read.xlsx(sheet = 1)
#write.table(da, "D:/project/R-use/yunan/data/a.xls", sep = "\t")

da <- "C:/Users/xueyj/Desktop/qusetion2.xlsx" %>%
  read.xlsx()

cns <- da %>% colnames()

da %<>% set_colnames("a" %>% paste0(cns %>% seq_along())) %>% arrange(a1)

k <- da[, 15]
w <- which(k == unique(k)[1]) %>% length()
m <- which(k == unique(k)[2]) %>% length()

p <- ggplot(da)

p1 <- p +
  geom_bar(aes(x = a15, fill = a15)) +
  theme_bw() +
  labs(x = "性别", fill = "") +
  geom_text(x = 1, y = m + 1, label = m) +
  geom_text(x = 2, y = w + 1, label = w) +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  )

p2 <- p +
  geom_bar(aes(x = a16, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "年龄区间", fill = "")

p3 <- p +
  geom_bar(aes(x = a8, fill = a8), show.legend = F) +
  theme_bw() +
  theme(axis.text.x = element_text(angle = 90)) +
  coord_flip() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "普通坐便圈不满之处")

p4 <- p +
  geom_bar(aes(x = a14, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "是否推荐")

p5 <- p +
  geom_bar(aes(x = a10, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "坚持使用")


p6 <- p +
  geom_bar(aes(x = a9, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "能否提高安全卫生作用") +
  coord_flip()
p7 <- p +
  geom_bar(aes(x = a12, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "您觉得每次使用收费多少比较合理？", fill = "性别") +
  coord_flip()
p8 <- p +
  geom_bar(aes(x = a14, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "请问您会向朋友推荐使用上策隔菌坐便圈吗？", fill = "性别") +
  coord_flip()

p9 <- p +
  geom_bar(aes(x = a18, fill = a15)) +
  theme_bw() +
  theme(panel.border = element_blank(),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        legend.background = element_blank(),
  ) +
  labs(x = "改建建议", fill = "性别") +
  coord_flip()

#ggsave(p1,filename = "C:/Users/xueyj/Desktop/a1.jpg")
#ggsave(p2,filename = "C:/Users/xueyj/Desktop/a2.jpg")
#ggsave(p3,filename = "C:/Users/xueyj/Desktop/a3.jpg")
#ggsave(p4,filename = "C:/Users/xueyj/Desktop/a4.jpg")
#ggsave(p5,filename = "C:/Users/xueyj/Desktop/a5.jpg")
#ggsave(p6,filename = "C:/Users/xueyj/Desktop/a6.jpg")
#ggsave(p7,filename = "C:/Users/xueyj/Desktop/a7.jpg")
#ggsave(p8,filename = "C:/Users/xueyj/Desktop/a8.jpg")
#ggsave(p9,filename = "C:/Users/xueyj/Desktop/a9.jpg")

#res <- ggarrange(p1,p2,p3,p4,p5,p6,p7,p8,p9,ncol=3,nrow = 3)
#ggsave(res,filename = "c:/Users/xueyj/Desktop/res.jpg",height = 40,width = 40)